//
//  MineIDTableViewController.m
//  GiftItems
//
//  Created by lanou3g on 15/9/22.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "MineIDTableViewController.h"
#import "BlurImageView.h"
#import "MineSecondTableViewCell.h"
#import "MIneHeaderView.h"
#import "MIneIDAndRoleTableViewController.h"
@interface MineIDTableViewController ()
@property(nonatomic, strong) NSArray *sexArr;
@property(nonatomic, strong) NSArray *roleArr;
@property(nonatomic, strong) NSArray *genderArr;
@property(nonatomic, strong) NSString *gender;
@property(nonatomic, strong) NSString *role;
@end

@implementation MineIDTableViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerClass:[MineSecondTableViewCell class] forCellReuseIdentifier:@"Cell"];
    self.tableView.backgroundColor = kRGB(255.0, 230.0, 255.0);
    self.tableView.alwaysBounceHorizontal = NO;
    self.genderArr = @[@"我的性别:",@"我的角色:"];
    self.sexArr = @[@"男",@"女"];
    self.roleArr = @[@"初中生",@"高中生",@"大学生",@"职场新人",@"资深工作党"];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendGender:) name:@"gender" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendRole:) name:@"role" object:nil];
}

// 视图消失时,移除观察者
- (void)dealloc {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"gender" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"role" object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
// 接受性别的通知
- (void)sendGender:(NSNotification *)no {
    // 移除上次保存的性别信息
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"gender"];
    [[NSUserDefaults standardUserDefaults] setObject:no.object forKey:@"gender"];
}

// 接受角色的通知
- (void)sendRole:(NSNotification *)no {
    // 移除上次保存的角色信息
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"role"];
    [[NSUserDefaults standardUserDefaults] setObject:no.object forKey:@"role"];
}
// 视图将要出现时,刷新表示图
- (void)viewWillAppear:(BOOL)animated {
    [self.tableView reloadData];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MineSecondTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    cell.title.text = self.genderArr[indexPath.row];
    
    if (indexPath.row == 0) {
        cell.idLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"gender"];
       
    }else {
        cell.idLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"role"];
    }
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    MIneHeaderView *headView = [[MIneHeaderView alloc] init];
    headView.picImage.hidden = YES;
    return headView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 45;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MIneIDAndRoleTableViewController *IDRoleVC = [[MIneIDAndRoleTableViewController alloc] init];
 
    if (indexPath.row == 0) {
        IDRoleVC.arrray = self.sexArr;
        IDRoleVC.myTitle = self.genderArr[0];
    }else {
        IDRoleVC.arrray = self.roleArr;
        IDRoleVC.myTitle = self.genderArr[1];
    }
    [self.navigationController pushViewController:IDRoleVC animated:YES];
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
